package com.liuwei.desktop.app;

import java.lang.Thread.UncaughtExceptionHandler;

import com.liuwei.desktop.common.ExceptionUtils;

public class GlobalExceptionHandler implements UncaughtExceptionHandler{

	@Override
	public void uncaughtException(Thread t, Throwable ex) {
		StackTraceElement[] stackElements = ex.getStackTrace();
		StringBuilder builder = new StringBuilder();
        if (stackElements != null) {            
            for (int i = 0; i < stackElements.length && i<15; i++) {
            	builder.append(stackElements[i].getClassName()+"."+stackElements[i].getMethodName());
            	builder.append("("+stackElements[i].getFileName());
            	builder.append(":"+stackElements[i].getLineNumber()+")");
            	builder.append("\r\n");
            }
        }
		ExceptionUtils.alertException(ex.getMessage()+"\r\n"+builder.toString());
	}

}
